﻿using Microsoft.EntityFrameworkCore;
using Stock;
using Stock.Input;
using Stock.Output;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Vouchers.InStockVouchers;
using Vouchers.OutStockVouchers;

namespace Vouchers
{
    public class OutStockVoucherService : ApplicationService, IOutStockVoucherService, IOutVoucherStockService
    {
        private readonly IRepository<OutStockVoucher, Guid> _outStockRepository;
        private readonly IRepository<OutStockVoucherDetail, Guid> _outStockDetailRepository;
        public OutStockVoucherService(IRepository<OutStockVoucher, Guid> outStockRepository,
                                     IRepository<OutStockVoucherDetail, Guid> outStockDetailRepository)
        {
            _outStockRepository = outStockRepository;
            _outStockDetailRepository = outStockDetailRepository;
        }
        public async Task<List<OutStockOutput>> GetOutStock(GetStockInput input)
        {
            var query = from a in (await _outStockRepository.GetQueryableAsync())
                        join b in (await _outStockDetailRepository.GetQueryableAsync()) on a.VoucherCode equals b.VoucherCode
                        where input.VoucherCodes.Contains(a.VoucherCode)
                        select new OutStockOutput
                        {
                            DeptId = a.InWarehouseId,
                            DeptName = a.InWarehouseName,
                            ProductCode = b.ProductCode,
                            ProductName = b.ProductName,
                            Count = b.OutCount,
                            Price = b.Price,
                            ProductBatch = b.ProductBatch,
                            ProductDate = b.ProductDate,
                            ExpiryDate = b.ExpiryDate,
                            TrackCode = b.TrackCode,
                            ProductClassName = a.ProductClassName,
                            ProductClassId = a.ProductClassId,
                            ManufactureId = b.ManufacturerId,
                            ManufactureName = b.ManufacturerName,
                            Specification = b.Specification,
                            UseUnit = b.Unit
                        };

            var dto = await query.ToListAsync();
            return dto;
        }
        public async Task<List<InStockOutput>> GetInStock(GetStockInput input)
        {
            throw new NotImplementedException();
            

        }
    }
}
